<template>
  <div style="background-color: #FFFFFF; padding: 20px;">
    <div>
      <div style="margin: 0 0 10px;float: left;">
        <router-link :to="{name: 'moduleAdd'}">
          <el-button type="primary" plain>添加</el-button>
        </router-link>
        <el-button type="danger" plain @click="delObjs()">删除</el-button>
      </div>

      <div style=" float: right;">
        <el-input placeholder="请输入模块名称" v-model="inputObjName" class="input-with-select">
          <el-button slot="append" icon="el-icon-search" @click="inputFunc()"></el-button>
        </el-input>
      </div>

      <div>
        <!--内容组件-->
        <el-table
          ref="multipleTable"
          :data="tableData"
          style="width: 100%"
          tooltip-effect="dark"
          @selection-change="handleSelectionChange">

          <el-table-column
            type="selection"
            width="55">
          </el-table-column>

          <el-table-column
            prop="id"
            label="ID"
            width="50">
          </el-table-column>
          <el-table-column
            prop="name"
            label="模块名称"
            width="200">
          </el-table-column>

          <el-table-column
            prop="module_key"
            label="模块key"
            width="200">
          </el-table-column>

          <el-table-column
            label="所属项目"
            width="180">
            <template slot-scope="scope">
              <el-popover trigger="hover" placement="top">
                <p>项目ID: {{ scope.row.project_info.id }}</p>
                <p>项目名称: {{ scope.row.project_info.name }}</p>
                <p>项目描述: {{ scope.row.project_info.describe }}</p>
                <div slot="reference" class="name-wrapper">
                  <el-tag size="medium">{{ scope.row.project_info.name }}</el-tag>
                </div>
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column
            prop="describe"
            label="描述"
            width="500">
          </el-table-column>

          <el-table-column
            label="测试人员"
            width="100">
            <template slot-scope="scope">
              <el-popover trigger="hover" placement="top">
                <p>用户ID: {{ scope.row.testers_info.id }}</p>
                <p>用户姓名: {{ scope.row.testers_info.name }}</p>
                <p>用户账号: {{ scope.row.testers_info.username }}</p>
                <div slot="reference" class="name-wrapper">
                  <el-tag size="medium">{{ scope.row.testers_info.username }}</el-tag>
                </div>
              </el-popover>
            </template>
          </el-table-column>

          <el-table-column
            label="开发人员"
            width="100">
            <template slot-scope="scope">
              <el-popover trigger="hover" placement="top">
                <p>用户ID: {{ scope.row.developer_info.id }}</p>
                <p>用户姓名: {{ scope.row.developer_info.name }}</p>
                <p>用户账号: {{ scope.row.developer_info.username }}</p>
                <div slot="reference" class="name-wrapper">
                  <el-tag size="medium">{{ scope.row.developer_info.username }}</el-tag>
                </div>
              </el-popover>
            </template>
          </el-table-column>

          <el-table-column
            prop="create_time"
            label="创建日期"
            width="200">
          </el-table-column>

          <el-table-column
            prop="update_time"
            label="更新日期"
            width="200">
          </el-table-column>

          <el-table-column prop="status" label="类型" width="120">
            <template slot-scope="scope">
              <el-select size="mini" v-model="scope.row.status" disabled placeholder="请选择类型">
                <el-option
                  v-for="(item,index) in optionsCommon"
                  :key="index"
                  :label="item.value"
                  :value="item.id">
                </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            label="操作"
            width="130">
            <template slot-scope="scope">
              <router-link :to="{name: 'ModulePage', query: { module_page_module_id: scope.row.id }}">
                <el-button type="text" size="small">页面</el-button>
              </router-link>
              <router-link :to="{name: 'moduleEdit', query: { module_id: scope.row.id }}">
                <el-button type="text" size="small">编辑</el-button>
              </router-link>
              <el-button :disabled="scope.row.status===1" type="text" size="small" @click="delObjs(scope.row.id)">删除</el-button>

            </template>
          </el-table-column>
        </el-table>
      </div>
      <!--分页组件-->
      <div class="block paging">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="pageSizes"
          prev-text="上一页"
          next-text="下一页"
          layout="total, sizes, prev, pager, next, jumper"
          :total="dataCount">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'Module',
    data() {
      return {
        // 需要搜索的项目名称
        inputObjName: '',  // 搜索功能实现的字符串
        // choices设置
        optionsCommon: [],  // 存储CommonChoices实际数据的列表
        // 分页设置
        currentPage: 1, //当前页码
        pageSize: 10,    //    每页的条数
        pageSizes: [10, 20, 30, 40],  // 可选每页显示条数
        dataCount: 0,  // 数据总条数

        // 数据设置
        ListDataURL: this.$http.moduleURL,  // 表格列表数据获取
        objID: 'module_id',
        tableData: [],  // 阿贾克斯获取的初始数据
        multipleSelection: [],  // 不能删，我也不知道是干嘛用的，删了会报错
      }
    },
    created() {
      // 发送啊假克丝请求
      this.objList();// 阿贾克斯获取的初始数据
      this.optionsCommon = this.getChoices.common  // 获取标准CHOICES
    },

    methods: {
      handleClick(row) {
        console.log(row);
      },
      // 修改每页显示条数
      handleSizeChange(val) {
        this.pageSize = val;  // 修改每页显示条数
        this.currentPage = 1;  // 修改页码
      },
      // 修改页码
      handleCurrentChange(val) {
        this.currentPage = val;  // 修改页码
      },

      // 发送啊假克丝请求 得到表格的原始数据
      objList() {
        this.$myTool.objList(this)
      },

      // 删除函数，调用了删除接口
      delObjs(objId) {
        this.$myTool.delObjs(objId,this)
      },

      //  按项目名称搜索的函数
      inputFunc() {
        this.$myTool.inputFunc(this)
      },

      // 不能删
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },

    },

    watch: {

      'pageSize': function (value) {
        this.objList();
      },
      'currentPage': function (value) {
        this.objList();
      }
    },

    computed: {
      getChoices() {
        return this.$store.state.choicesInfo
      }
    },
  }
</script>

<style scoped>
  .paging {
    padding-top: 20px;
  }

</style>
